if(window.CH == undefined){
    window.CH = {};
}


CH.VC3={
    packagename:"basic",
    undoflag:0,
    imagesuploaded:0,
    sDiv:"",
    xangle:0,
    counter:0,
    totalcount:0,
    count:0,
    tempdivid:"",
    tempspanid:"",
    items:{},
    tosave:"",
    angle:0,
    selecteditem:0,
    imageortext:0,
    imgparam:null,
    filename:"",
    jcrop_api:0,
    boundx:0,
    boundy:0,
    copied:null,
    lastaction:"",
    prevstate:"",
    element:"",
    lastalignstate:"Ralign",
    lastfontfam:"serif",
    lastfontsize:"",
    lastcolor:"",
    lasttext:"",
    loaded: false,
    appended: false,
    DivBeingRotated:false,  
    mouseStartAngle:0,    
    DivStartAngle:false  ,
    dirname:"bgimgs2/",
    result:"",
    
    init:function(){
        
        CH.VC3.uninitall();
        CH.VC2.uninitall();
        CH.VC.uninitall();

        
        
        
        
        this.initdestroydrop();
        
        this.items= new Array();
        this.undos= new Array();
        this.redos= new Array();
        
        this.initSelection();
        this.initunselect();
        this.initBtAddField();
        this.inituploadPic();
        
        this.initBtRemField();
        this.initBtedit();
        this.initImageedit();
        this.initResizeforimage();
        this.initResizefortext();
        this.initDrag();
        this.initHideCornerButtons();
        this.initeditinplace();    
        this.initchoose_design();
        this.initadd_text();
        
        
        this.initeditablediv();
        //this.Imsmart();
        this.to_back();
        this.to_front();
        makeback();
        matchaddressfromback();
        this.initrotatedivs();
    

    },
    initeditablediv:function(){
        $.ajax({
            type: "POST",
            url:"getwhitearea.php",
            data:{
                src:CH.VC3.result    //sending image number coming from common load designs;
            } ,
            //success:function(data){
            success:function(data){
                //  alert(data);     // top or left overlay ka yahan say aa raha hai
                var temp = new Array();

                temp = data.split(' ');

                var bottom2=temp[0]+'px';
            // alert (bottom2);
             //   bottom2=bottom2.substring(9);
                var left=temp[1]+'px';
            // alert (left);
             var width=temp[2]+'px';
           //  alert (width);
             var height=temp[3]+'px';
           //  alert (height);                               
                                            
                //$(".drop").append("<div class='dead' style='bottom:"+bottom2+"; left:"+left+"; width:"+width+"; min-height:"+height+";'></div>");        
    $(".drop").append("<div class='overlaydb' style='bottom:"+bottom2+"; left:"+left+"; width:"+width+";'></div>");                
        
    }
        }); 
        
        
    },
    uninitall:function(){
        $(".back").remove();
        // alert("calling dead");
        $(".probtn").unbind("click");
        $(".txtbtn").unbind("click");
        $(".uplodtbtn").unbind("click");
        $('#fontList li').unbind("click");
        $("#predefinebg").unbind("click")
        $('span').unbind("dblclick");
        $(".drop div div").unbind("mousedown");
        $(".drop").unbind("click");
        $(".drop div").unbind("mouseup");
        $("#photoimg").unbind("change");
        $("#addButton").unbind("click");
        $('#backdivimg').unbind("click");
        $('#frontdivimg').unbind("click");
        $("#removeButton").unbind("click");
        $(".drop div div .delete-image").unbind("click");
        $(".drop div div").unbind("dblclick");
        $(".drop div div span .preview").unbind("dblclick");
        this.destroyDragResize();
        $(this.sDiv+" .drag-image").unbind("mousedown");
    },
    
    
    
    
    
    initdestroydrop:function(){
        
        $('.drop').empty();
        this.counter=0;
        this.totalcount=0;
        this.count=0;
    },
    
    
    
    to_back:function() {
        
        var oThis=this;
        $("#backdivimg").click(function(){
            alert("asdf");
            $('#backdivimg').hide();
            $('#frontdivimg').show();
            cmn_to_back(CH.VC3.packagename);
    
        });
    },
    
    
    
    to_front:function(){
        var oThis=this;
       
        $("#frontdivimg").click(function(){
           alert(CH.VC3.packagename);
            cmn_to_front(CH.VC3.packagename);
        });
    
    },
    
    
    
   
    
    initchoose_design:function() {
        
        var oThis=this;
        $(".probtn").click(function(){

            alert("This functionality is not completed yet");

        });
    },
    
    
    initadd_text:function() {
        
        var oThis=this;
        $(".txtbtn").click(function(){  
            oThis.html=0
            oThis.addbutton(oThis.undoflag,oThis.html);
    
        });
    },


      
    
    
    initFontFam:function() {  
        $('#fontList li').click(
            function(){
                var chosen = $(this).index();
                $('#fontSelector option:selected')
                .removeAttr('selected');
                $('#fontSelector option')
                .eq(chosen)
                .attr('selected',true);
                $('.selected').removeClass('selected');
                $(this).addClass('selected');
            });
    
    },
    
    
    
    
    
    Imsmart:function(){
        
        $.ajax({
            type: "POST",
            url:"getwhitearealocation.php",
            data:{
                src:CH.VC3.result    //sending image number coming from common load designs;
            } ,
            //success:function(data){
            success:function(data){
                //  alert(data);     // top or left overlay ka yahan say aa raha hai
                var temp = new Array();

                temp = data.split(' ');

                var bottom2=temp[0]+'px';
                bottom2=bottom2.substring(9);
                var left=temp[1]+'px';
                var width=temp[2]+'px';
                var height=temp[3]+'px';
                                            
                                            
                $(".drop").append("<div class='overlay' style='bottom:"+bottom2+"; left:"+left+"; width:"+width+"; min-height:"+height+";'></div>");        
            }
        }); 
        
    },
     
    initeditinplace:function() {
        $('span').live('dblclick', function() {
            // if success message is visible, remove it
            $(this).find('.ok').remove();
        
            // if already in input mode, return
            if ($(this).hasClass('inputMode')) {
                return true;
            }
        
            // change to input mode
            var tartalom = $(this).html();
        
        
            $(this)
            .empty()
            
            .append("<input type='text' id='input2' style='background-color:transparent;' value='" + tartalom + "'>")
            // style='float:left;'
            //.append("<input type='button' style='float:left;' value='S' class='save'>")
            .addClass('inputMode');
            
            
            $("#input2").unbind("focusout");
            $("#input2").focusout(function() {
                // create success message
        
                //alert("eehaa");
                //var jSuccess = $("<span class='ok'> <img src='accept.png' /> Success</span>");
        
                // deactivate input mode
        
                //alert($(this).parent().prop("id")); span ki id
                $(this).parent().html($(this).val())
        
        
                //.html($(this).prev().val())
                //.append(jSuccess)
                .removeClass('inputMode');
        
                // animate success message
                //  $(jSuccess).delay(1500).fadeOut(500, function() {
                //      $(this).remove();
                // });
        
                // prevent jq_edit click handler
                return false;
            });
        });
    },
    
    
    
    
    destroyDragResize:function(){
        $(".drop div div").draggable( "destroy" );
        $(".drop div div").resizable( "destroy" );


    },
    initHideCornerButtons:function(){
        $(".drop div div .rotate-image").hide();
        $(".drop div div .delete-image").hide();
        $(".drop div div.drag-image").hide();
        
      
    },
    



    initSelection:function(){
        var oThis=this;
        $(".drop div div").mousedown(function(){
            var seldiv="#"+$(this).prop("id")
            oThis.selectelement(seldiv);
        
        });
        
        
    },
    
    selectelement:function(proDivId){
        
        $(".drop div div").removeClass("highlight");
            
        // window.console.log("select");
        $(".drop div div .rotate-image").hide();
        $(".drop div div .delete-image").hide();
        $(".drop div div .drag-image").hide();
        //alert("selection "+$(this).prop("id"));
        //this.sDiv="#"+$(this).prop("id");
            
        this.sDiv=("#"+($(proDivId).prop("id")));
        //window.console.log(this.sDiv);
        $(this.sDiv).addClass("highlight");
        $(this.sDiv+" .rotate-image").show();
        $(this.sDiv+" .drag-image").show();
        $(this.sDiv+" .delete-image").show();
        
        this.selecteditem =this.sDiv.substr(this.sDiv.length - 1);
        this.selecteditem--;
            
            
        //window.console.log("In Select sDiv: "+this.sDiv);
        this.initDrag();
    },
    
    
    

    initunselect:function(){
        var oThis=this;
        $(".drop").unbind("click");
        $(".drop").click(function(e) {
            //$(".drop").click(function(e) {
            oThis.unselectelement(e);       
                
        });
    
    },
    
    unselectelement:function(e){
        
        if($(e.target).prop("id")=="drop")
        {
            $(".drop div div").removeClass("highlight");
            $(".drop div div .rotate-image").hide();
            $(".drop div div .delete-image").hide();
            $(".drop div div .drag-image").hide();
            this.sDiv="";
            return true;
        }
           
        return false;
    },


    initRelBtRotate:function(){    //display corner buttons
        var oThis=this;
        $(".drop div").unbind("mouseup");
        $(".drop div").mouseup(function (e){
            $(oThis.sDiv+" .drag-image").show();
            $(oThis.sDiv+" .delete-image").show();
            $(oThis.sDiv+" .rotate-image").show();
        });
        
    },


    inituploadPic:function(){
        var oThis=this;
        
        
        
        $("#upphot").unbind("click");
        $("#upphot").click(function() {
        
            oThis.addimage();
        });
        
    },
 /*
    addimage:function(){
        
        alert("fe");
        var oThis=this;
        if(this.counter>2){
            alert("Only 3 new Fields");
            return false;
        }
        else{
        
        $(".outer").html(" <form id='imageform' method='post' enctype='multipart/form-data' action='./ajaximage.php'>Upload your image <input type='file' name='photoimg' id='photoimg' /></form>");
        
        this.imageortext=1;
        
        $(".outer").dialog({
            modal: true,
            open:function(event, ui){
            //$("#imagefrm").show();
                
            },
            buttons: {
                Ok: function() {
                    
                    oThis.addbutton();
                    $(".drop div #demobs"+oThis.totalcount+" span").html('');
        
        
                    $(".drop div #demobs"+oThis.totalcount+" span").html('<img src="imagesapp/loading.gif" alt="Uploading...."/>');
                    
        
       
            
                    $("#imageform").ajaxForm({
                        success:       oThis.showResponse,
                        target: $(".drop div #demobs"+oThis.totalcount+" span")
                
                    //                Success: function(responseText, statusText, xhr, $form){
                    //                            whatever you want to do in success goes here
                    //                        }
                    }).submit();
        
                    $( this ).dialog( "close" );
                }    
            }
            
            
        });
        }
    },*/
    
     addimage:function(){
        var oThis=this;
        
        if(this.counter>2){
            alert("Only 3 new Fields");
            return false;
        }
        else{
        $("#outer").html(" <form id='imageform' method='post' enctype='multipart/form-data' action='./ajaximage.php'>Upload your image <input type='file' name='photoimg' id='photoimg' /></form>");
        
        this.imageortext=1;
        
        $("#outer").dialog({
            modal: true,
            open:function(event, ui){
            //$("#imagefrm").show();
                
            },
            buttons: {
                Ok: function() {
                    
                    oThis.addbutton();
                    $(".drop div #demobs"+oThis.totalcount+" span").html('');
        
        
                    $(".drop #div #demobs"+oThis.totalcount+" span").html('<img src="imagesapp/loading.gif" alt="Uploading...."/>');
                    
                    //alert($("#imageform input").val());
       
                    //alert(oThis.totalcount);
                    $("#imageform").ajaxForm({
                        success:       oThis.showResponse,
                        target: $(".drop div #demobs"+oThis.totalcount+" span")
                
                    //                Success: function(responseText, statusText, xhr, $form){
                    //                            whatever you want to do in success goes here
                    //                        }
                    }).submit();
                    $( this ).dialog( "close" );
                }    
            }
            
            
        });
        }
    },
    showResponse:function (responseText, statusText, xhr, $form)  { 
        //this<--span
        //alert($(this).children().prop("id"));
       
        $(".outer").html("");
        
        /*
        temp=$(this).parent().css("height");
        alert(temp);
        var temp2=$(this).parent().parent().css("height");
        alert(temp2);
        $("#"+temp+" img").css("width", temp2);
        
        */
        
        var temp=$(this).prop("id");
        //alert(temp);
        //alert($("#"+temp+" img").prop("id"));
        var temp2=$(this).parent().parent().css("height");
        
        $("#"+temp+" img").attr("style", "width:"+temp2+"");
        
        $(this).parent().resizable( "destroy" );
        var temp=$(this).children().prop("id");
        CH.VC3.imagesuploaded=CH.VC.imagesuploaded+1;
        temp=temp+CH.VC3.imagesuploaded;
        $(this).children().prop("id",temp);
        //alert($(this).children().prop("id",temp));
        
        var undo=new CH.undoredo;
        CH.VC3.undos.push(undo);
        CH.VC3.undos[CH.VC3.undos.length-1].id="#demo"+CH.VC3.totalcount;
        CH.VC3.undos[CH.VC3.undos.length-1].lastaction="Pupload";
        CH.VC3.undos[CH.VC3.undos.length-1].lastvalue=responseText;
        
       

        CH.VC3.initImageedit();
  
    //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.'); 
    }, 
 
   
 
    
    initBtAddField:function(){
        var oThis=this;
        $("#addButton").unbind("click");
        $("#addButton").click(function () {
            
            oThis.undoflag=0
            oThis.html=0
            oThis.addbutton(oThis.undoflag,oThis.html);           
        });
        
    },
    
    
    addbutton:function(flag,html){
       
        // alert("seriously");
        var oThis=this;
        if(this.counter>2){
            alert("Only 3 new Fields");
            return false;
        }   
	
        else{
            //  alert("I'm in add button");
            var it= new CH.item();
            //it.say("crap");
            //it.isBold=1;
            //alert(JSON.stringify(it));
            this.items.push(it);
            //alert (this.items[0]);
                        
                        
            count=this.totalcount+1;
            
            if(html==0)
            {
                //var temp_html="<div id='demobs"+ count +"' class='demobs' align='right'><img class='rotate-image' src='imagesapp/rotateimg.png' width='20' height='20' /><img class='drag-image' src='imagesapp/move.png' width='20' height='20' /><img class='delete-image' src='imagesapp/del.png' width='20' height='20' /><span id='span"+ count +"'>Enter Text Here</span></div>";
                var temp_html="<div id='demobs"+ count +"' class='demobs' align='right'><img class='rotate-image' src='imagesapp/rotateimg.png' width='20' height='20' /><img class='drag-image' src='imagesapp/move.png' width='20' height='20' /><img class='delete-image' src='imagesapp/del.png' width='20' height='20' /><span id='span"+ count +"'>Enter Text Here</span></div>";    
            }
            else
            {
                var temp_html="<div id='demobs"+ count +"' class='demobs' align='right'><img class='rotate-image' src='imagesapp/rotateimg.png' width='20' height='20' /><img class='drag-image' src='imagesapp/move.png' width='20' height='20' /><img class='delete-image' src='imagesapp/del.png' width='20' height='20' /><span id='span"+ count +"'>"+html+"</span></div>";
            }
            
            $(".drop .overlaydb").append(temp_html);
            
            //this.sDiv="#demobs"+count;
            //alert(this.sDiv);
            
            //alert($("#demobs"+count+" span").html());
            //alert($(".drop demobs"+count).html);
            //CH.VC3.items[this.selecteditem].innertext=($("#demobs"+count+" span").html());
            CH.VC3.items[count-1].innertxt=($("#demobs"+count+" span").html());
            //selector();
          //  alert($("#demobs").html());
            oThis.initSelection();
            oThis.destroyDragResize();
            oThis.initDrag();
            
            if(this.imageortext==0)
            {
                oThis.initResizefortext();
            }
            else
            {
                oThis.initResizeforimage();
                    
                this.imageortext=0;
            }
            
            oThis.initBtedit();
            oThis.initImageedit();
            oThis.initrotatedivs();
            oThis.initHideCornerButtons();
            oThis.initBtRemField();
            
            oThis.totalcount=this.totalcount+1;
            oThis.counter++;
            
            
            
            if(flag==0)      
            {
                var undo=new CH.undoredo;
                this.undos.push(undo);
            
                this.undos[this.undos.length-1].id="#demobs"+this.totalcount;
                this.undos[this.undos.length-1].lastaction="Addfield";
            }
            
            return true;
        }
 
    },
    
    initBtRemField:function(){
        var oThis=this;
        $("#removeButton").unbind("click");
        $("#removeButton").click(function () {
            //window.console.log("#removeButton");
            
            
            oThis.undoflag=0
            oThis.removebutton(oThis.sDiv,oThis.undoflag);
            
        });
        $(".drop div div .delete-image").unbind("click");
        $(".drop div div .delete-image").click(function () {
            
            
            oThis.removebutton(oThis.sDiv,oThis.undoflag);
            
        });
	
    },
      
    removebutton:function(proDivId,flag){
        
        
        
        if(this.counter==0){
            alert("No more textbox to remove");
            return false;
        }   
        else
        {
            
            if (proDivId!="")
            {
                
                if(flag==0){
                    var undo=new CH.undoredo;
                    this.undos.push(undo);
                }
                
                //alert(proDivId);
                this.tempdivid=$(proDivId).attr('id');
                this.tempspanid=$(proDivId+" span").attr('id');
                
                //alert($(proDivId).html());
                if(flag==0){
                    this.undos[this.undos.length-1].lastvalue=$(proDivId+" span").html();
                }
                
                $(proDivId).remove();
                $(".drop div #demobs"+this.totalcount).prop('id',this.tempdivid);
                $(".drop div #span"+this.totalcount).prop('id',this.tempspanid);
                this.totalcount--;
                this.counter--;
                this.sDiv="";
                //alert(this.sDiv);

                if(flag==0){
                    this.undos[this.undos.length-1].id=proDivId;
                    this.undos[this.undos.length-1].lastaction="Remfield";
                }
                
                
            }  
            else{
                
            {
                    alert("please select any element to delete");
                }
                
            }
        }
 
    },
    
    
    initBtedit:function(){
        var oThis=this;
        $(".drop div div").unbind("dblclick");
        $(".drop div div").dblclick(function(e) {
            
            
            e.stopImmediatePropagation();
            e.preventDefault();
            //var spanid="#"+($(this).prop("id"));
            
            
            if($(this).children().children().prop("class")!="preview")
            {
                
                
                oThis.editor();
            }
            else
            {
                return;
            }
            
            return
        });
        
    },
    
    editor:function(){
    
        var oThis=this.sDiv+" span";


        if ($(this.sDiv).children(" span").hasClass('inputMode')) {
            window.console.log($(this.sDiv).children(" span").prop("id"));
            return true;
        }
        
        var tartalom = $(this.sDiv).children(" span").html();
        //alert(tartalom);
        var undo=new CH.undoredo;//
        this.undos.push(undo);//
        this.undos[this.undos.length-1].lastvalue=tartalom;//        
        this.undos[this.undos.length-1].id=("#"+$(this.sDiv).prop("id"))//
        $(this.sDiv).children(" span")
        .empty()
        .append("<input type='text' id='input2' style='background-color:transparent;' value='" + tartalom + "'>")
        .addClass('inputMode');
        $("#input2").mouseout(function() {
            
            //alert($(this).prop("id"));
            $(this).parent().html($(this).val())
            .removeClass('inputMode');
            //CH.VC3.initrotatedivs();//
            var index=($(oThis).prop("id")).substr($(oThis).prop("id").length-1);//
            CH.VC3.items[index-1].innertxt=$(this).val();//
            CH.VC3.undos[CH.VC3.undos.length-1].nextvalue=$(this).val();//
            CH.VC3.undos[CH.VC3.undos.length-1].lastaction="Edit";//


            return false;                    
        });
    },
	
 
	
    
    initImageedit:function(){
        var oThis=this;
        $(".drop div div span .preview").unbind("dblclick");
        $(".drop div div span .preview").dblclick(function() {
            var imgsrc=($(this).prop('src'));
            //alert(imgsrc);
            //var ext =;
            // $("#myimg").attr("src", "/myimg.jpg?"+d.getTime());
            $("#target").removeAttr('src').prop('src',imgsrc);
            
            //alert($("#target").prop('src'));
            //$("#preview").removeAttr('src').prop('src',imgsrc);   current
            oThis.editorz(this);
            
        });
        
    },
    
    
    
  
    editorz:function(img){
        
        
        //alert($(img).prop("src"));
        var oThis=this;
        if($(img).prop("id")=="upimg_crop")
        {
            alert("Cannot crop an image more than once!");    
            
        }
        
        else{
            
            
            //alert($(img).prop("id"));//this gives id of image
            var temp=($(img).prop("src"));
            //alert($('#target').prop("src"));
            var imgStr = "<img class='cropImage' src='"+temp+"' />";
            //$('#target').prop("src",temp);
            //alert($('#target').prop("src"));
            $('#target').html(imgStr);
        
       
            $("#cropper").dialog("destroy");
            $("#cropper").dialog({
                modal: true,
                width:"auto",
                height:"auto",
                open:function(event, ui){
                    $($('#target .cropImage')[0]).Jcrop({
                        onChange: oThis.updateCoords,
                        onSelect: oThis.updatePreview,
                        aspectRatio: 1
                    },function(){
                        // Use the API to get the real image size
                        var bounds = this.getBounds();
                        oThis.boundx = bounds[0];
                        oThis.boundy = bounds[1];
                        // Store the API in the jcrop_api variable
                        oThis.jcrop_api = this;
                    });
                },
                buttons: {
                    Crop: function() {
                        var imgs=($(img).prop('src'));
                    
                    
                        //$("#target").prop('src',imgs);
                    
                        //alert($("#target").prop('src'));
                        var url=$("#target").prop('src');       
                        oThis.filename = url.substring(url.lastIndexOf('/')+1);
                        oThis.filename="uploads/"+oThis.filename;
                        var ext =("."+oThis.filename.split('.').pop());
                        var output = oThis.filename.substr(0, oThis.filename.lastIndexOf('.')) || oThis.filename;
                        var updatedfilename=(output+"1"+ext);
                    
                    
                    
                        $.ajax({
                        
                            type: "POST",
                            url:"crop.php",
                            data:{
                                src:oThis.filename, //here
                                x:CH.VC3.imgparam.x,
                                y:CH.VC3.imgparam.y,
                                w:CH.VC3.imgparam.w,
                                h:CH.VC3.imgparam.h
                            } ,
                            //success:function(data){
                            success:function(){
                                //var temp=$(img).prop('id');
                                //temp=temp+"_crop";
                            
                                //$(img).prop('id',temp);
                                $(img).prop('id',"upimg_crop");
                                //alert($(img).prop("id"));
                                $(img).prop('src',updatedfilename);    //here                    
                        
                            }
                        });
                    
                        oThis.jcrop_api.destroy();    
                    
                        $( this ).dialog( "close" );
                    }
            
                }
            });
        }
    },
  
  
 
    updateCoords:function(c)
    {
        var oThis=this;
        //  alert(oThis);
        CH.VC3.imgparam=c;
    
    },

    checkCoords:function()
    {
        if (parseInt($('#w').val())) return true;
        alert('Please select a crop region then press submit.');
        return false;
    },
  
  
  
  
    
    
    initResizefortext:function(){
        var oThis=this;
        oThis.destroyDragResize();
        $(".drop div div").resizable({
            //handles: "all",
            aspectRatio:false,
            containment: "parent",
            minWidth: 40,
            minHeight: 40,
            resize:function(event, ui) {
                //alert(oThis.sDiv);
                $(oThis.sDiv+"  span").css('font-size', $(oThis.sDiv).height() / 3); 
                
            }
        });
    },
    
    
    initResizeforimage:function(){
        var oThis=this;
        oThis.destroyDragResize();
        $(".drop div div").resizable({
            //handles: "all",
            aspectRatio:true,
            containment: "parent",
            minWidth: 40,
            minHeight: 40,
            resize:function(event, ui) {}
        });
    },
    
    
 
    
    
    
    initDrag:function(){
        var oThis=this;
        //window.console.log("in drag sDiv: "+ oThis.sDiv);
        $(".drag-image").unbind("mousedown");
        $(".drag-image").mousedown(function(){
            
            //alert("dragging");
            oThis.dragit();    
        });
    
    },
    
    dragit:function(){
        //alert("moving");
        var oThis=this;
        //alert($(this.sDiv).prop("id"));
        this.destroyDragResize();
        window.console.log($(oThis.sDiv));
        
        
        $(oThis.sDiv).draggable({
            containment: "parent",
            drag: function(){
                //alert("dragging");  
                window.console.log("dragging");
                window.console.log($(oThis.sDiv));
                $(".delete-image").hide();
                $(".rotate-image").hide();
                 
                var offset = $(this).offset();
                var xPos = offset.left;
                var yPos = offset.top;
                
                //alert(xPos);
                CH.VC3.items[oThis.selecteditem].xposition=xPos;
                CH.VC3.items[oThis.selecteditem].yposition=yPos;
          
            }        
    
        }) ;
        
        this.lastaction="Drag";
        this.element=this.sDiv;
    
        
        
    
    },
    
    
    
    
    putBackGroundInddforinitialscreen:function(bannertemphtml) //initial wallpaper selection
    {
        _packageType = 'BASIC';
        loadDesigns(CH.VC3.packagename, false);			
    },
    



fl_rotate:false,
    initrotatedivs:function() {
        var pw;
        var oThis=this;
        
        //alert("sdf");
        //$(".drop div div .rotate-image").unbind("mousedown");
        $(".drop .rotate-image").mousedown(function (e){
            //alert("ok");
            hookRotation(oThis, e);
            return;
            
        });
       
        //$(document).unbind("mouseup");
        $(document).mouseup(function (e){
            
            if(oThis.fl_rotate)
            {                
                oThis.initDrag();
                
                if($(oThis.sDiv).children("span").children().prop("class")!="preview")
                {
                    oThis.initResizefortext();
                }
                else
                {
                    oThis.initResizeforimage();
                }
                
                var ele= $(oThis.sDiv);
                ele.unbind( 'mousemove' );
                ele.draggable({
                    containment: 'parent'
                });
                ele=0;
                oThis.fl_rotate=false;
            }
        });
        
        
        
        
    },
    rotateOnMouse:function (e,pw) 
    {                   
        rotateOnMouse(this, e, pw);
    }
   
}